fix(sys): report host arch via IsWow64Process2 on Windows ARM64#705
Merged
Conversation
platform.machine() returns the process architecture, so an x64 Python running under ARM64 emulation reports "AMD64" — the project venv hits this because torch has no Windows-ARM64 wheel. PROCESSOR_ARCHITEW6432 is empty on Snapdragon X (Prism emulation does not set it), so detect the native machine via IsWow64Process2 and fall back to platform.machine().
- Document that _IMAGE_FILE_MACHINE_TO_NAME is intentionally limited to the host architectures Windows 11 ships on (no 32-bit ARM, no IA64); unmapped values fall through to None and log at debug level. - Log ctypes.get_last_error() when IsWow64Process2 returns 0 so a regression does not silently fall back to platform.machine(). - Hoist kernel32 + IsWow64Process2 to module scope, gated by sys.platform == "win32", so LoadLibrary runs once per process and non-Windows callers don't hit a ctypes.WinDLL error path. - Add an explicit `if sys.platform != "win32": return None` guard in _get_windows_native_machine to match the pattern used in _preload_bundled_onnxruntime_dll (#689). - Split the raw Win32 query (_query_native_machine_via_win32) from the name mapping (_get_windows_native_machine) and parametrize tests over IMAGE_FILE_MACHINE_* integers so a rename of "ARM64" → "Arm64" in the table fails the test instead of silently shipping.
CodeQL flagged "Module is imported with 'import' and 'import from'" because the prior commit mixed `import ctypes as _ctypes` with `from ctypes import wintypes as _wintypes`. Hoist `import ctypes` and `import ctypes.wintypes` to the top of the module and reference the qualified names; drop the function-local re-import of ctypes.
xieofxie
approved these changes
May 22, 2026
Contributor
xieofxie
left a comment
There was a problem hiding this comment.
if you tested, just approved
DingmaomaoBJTU
pushed a commit
that referenced
this pull request
May 22, 2026
## Summary - Fixes #704 — `winml sys` showed `Machine: AMD64` on Windows ARM64 hosts. - `platform.machine()` returns the process arch, so an x64 Python on ARM64 (under Prism emulation) misreports the host. `PROCESSOR_ARCHITEW6432` is empty on Snapdragon X, so it's not a reliable fallback. - Added `_get_windows_native_machine()` using the Win32 `IsWow64Process2` API to read the native machine type; falls back to `platform.machine()` if the call fails. - Added unit coverage for the emulation case and the fallback path; updated existing Windows tests to mock the new helper so they stay deterministic across host architectures. ## Verification - `winml sys` on a Snapdragon X box now shows `Machine: ARM64` (was `AMD64`). - `uv run pytest tests/unit/sysinfo/test_sysinfo.py` → 14 passed. - `ruff check` clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
winml sysshowedMachine: AMD64on Windows ARM64 hosts.platform.machine()returns the process arch, so an x64 Python on ARM64 (under Prism emulation) misreports the host.PROCESSOR_ARCHITEW6432is empty on Snapdragon X, so it's not a reliable fallback._get_windows_native_machine()using the Win32IsWow64Process2API to read the native machine type; falls back toplatform.machine()if the call fails.Verification
winml syson a Snapdragon X box now showsMachine: ARM64(wasAMD64).uv run pytest tests/unit/sysinfo/test_sysinfo.py→ 14 passed.ruff checkclean.